Microcomputer and encoding system for executing peripheral function instructions

ABSTRACT

A microcomputer that can process plural tasks time-divisionally and in parallel, wherein one of a plural programs described by one of the tasks is described as a looped specific task in which the increment of program addresses is fixed, a program counter is usable as a timer counter, a peripheral function instruction is described in the specific task, the peripheral function instruction is set so as to indicate one or more general-purpose registers as an operand. The CPU executes the peripheral function instruction as one instruction and achieves information needed to execute the instruction by a general-purpose register and stores the execution result into the general-purpose registers. An instruction code encoding system includes an operation code and plural operands for indicating operation targets of an instruction in an instruction code and executing an instruction indicated by the operation code on the operation targets. When the operation targets indicated by the plural operands are set to a combination in which an execution result does not vary, the processing corresponding to an instruction different is executed.

CROSS REFERENCE TO RELATED APPLICATIONS

This application is a divisional of U.S. patent application Ser. No.11/330,237 filed on Jan. 12, 2006 and entitled MICROCOMPUTER ANDENCODING SYSTEM FOR INSTRUCTION CODE, and is based upon, claims thebenefit of priority of, and incorporates by reference the contents ofJapanese Patent Application Nos. 2005-9413 filed on Jan. 17, 2005, and2005-251317 filed on Aug. 31, 2005.

TECHNICAL FIELD

The technical field relates to a microcomputer that can executetime-divisional parallel processing on plural tasks, wherein at leastone of these tasks is a specific task in which a program looped so thatan increment of instruction addresses is fixed is described, and alsorelates to an encoding system for an instruction code executed by a CPU,and the CPU having an instruction decoder adopting the encoding system.

BACKGROUND

When a microcomputer constructed by adding a CPU with ROM, RAM and otherperipheral functions is applied to various user applications, usually,it is necessary to change the hardware of the microcomputer inconnection with functions required for each application, and thus thereis a problem that the number of variations of products is increased.

Therefore, there may be considered such a construction that an operationas a function is implemented by software. For example, JP-A-6-250857discloses a microcomputer in which two tasks (A, L) are subjected totime-divisional parallel processing in one CPU and execution of a branchinstruction is prohibited in the L-task to establish fix-looping,whereby the value of a program counter is used as a timer or runawaymonitoring processing of the A-task is executed.

However, in order to implement an “input capture” function of achievinga timer value in accordance with a level variation of a specific inputterminal or a more complicated peripheral function such as serialcommunication or the like in the microcomputer disclosed in the abovepublication, the program size is greatly increased.

Furthermore, JP-A-2004-38521 discloses a construction in which a prefixinstruction is disposed just before a target instruction described in aprogram and the function of the target instruction is extended inaccordance with the state of a flag set in the prefix instruction.

However, in the technique disclosed in JP-A-2004-38521, it is necessaryto insert the prefix instruction in order to extend the instructionfunction, and thus the program size is necessarily increased.

It is generally required that more kinds of instructions are installedin the CPU, and in order to satisfy this requirement, it is necessary tocompress the size of the overall instruction code to a maximum. JapanesePatent No. 2,682,469 discloses one of these techniques. As shown in FIG.20, this technique is an encoding system of code-expanding an offsetoperand (lower-order bits (2 to 0) of offset) as an operation code fieldfor the same operation code (ope2) to thereby allocate pluralinstructions.

That is, the technique disclosed in the above Japanese Patent isestablished on the basis of the assumption that “0” is allocated to thelower-order bits of the offset field which will serve as bits for codeexpansion. Accordingly, this technique is not applicable to aninstruction code in which other parameters are set to the lower-orderbits.

SUMMARY

In view of the foregoing situation, it is a concern of this disclosureto provide a microcomputer that can implement various peripheralfunctions by software under the condition that an increase of theprogram size is suppressed to a maximum.

According to a first aspect, a CPU is designed so that a peripheralfunction instruction described in a specific task can be executed as oneinstruction. Information needed to execute the peripheral functionalinstruction is achieved from a general-purpose register indicated by anoperand, and also information concerning an execution result of theinstruction concerned is stored in a general-purpose register.Accordingly, description of a program for implementing a peripheralfunction by software is very simple, and the program size can bereduced. Furthermore, a bit of the general-purpose register can beoperated by an instruction which is normally prepared by the CPU.Therefore, in order to execute the peripheral function instruction, itis unnecessary to prepare a special instruction such as a prefixinstruction separately. The phrase “peripheral function is implementedby software” indicates that the peripheral function is implemented incooperation between the hardware corresponding to the internalconstruction of the CPU in the microcomputer and the program executed byCPU concerned.

According to a second aspect, the CPU achieves from the general-purposeregister edge indicating information which serves as a condition forachieve a timer value. If a previously sampled level of the inputterminal which is stored in the general-purpose register is comparedwith the present level of the present input terminal, it can be judgedwhether the achievement condition (rise-up or falling of edge) issatisfied or not. The value of the timer count achieved when thecondition is satisfied is stored as a capture value, and also a flagindicating that an input capture comes into effect is stored.Accordingly, by executing an input capture instruction after the edgeindicating information is set in the general-purpose register by anormal instruction in advance, the input capture function can beimplemented by software.

According to a third aspect, when executing a sampling compareinstruction, the CPU achieves a compare period value set in ageneral-purpose register. Furthermore, the data achieved by accumulatingand adding the compare period value for every sampling timing are storedas a compare value in the general-purpose register. When the comparevalue concerned matches a timer counter value, the sampling result and asatisfaction flag are stored in the general-purpose register.Accordingly, by executing a sampling compare instruction after thecompare period value is set in the general-purpose register on the basisof a normal instruction in advance, the sampling compare function can beimplemented by software.

According to a fourth aspect, when an input compare set instruction isexecuted, the CPU achieves the compare period value set in thegeneral-purpose register and edge indicating information of the inputterminal which corresponds to a compare set condition. If the compareset condition is satisfied, the value achieved by adding the timercounter value at that time with the compare period value is stored as acompare value in the general-purpose register, and also the satisfactionflag is stored. Accordingly, the compare period value and the edgeindicating information are set in the general-purpose register by thenormal instruction in advance, and then the input compare setinstruction is executed, whereby the input compare set function can beimplemented by software.

According to a fifth aspect, when a condition-added sampling instructionis executed, the CPU judges whether a condition flag is set in thegeneral-purpose register. If the setting of the condition flag isrecognized, the sampling result and the satisfaction flag are stored inthe general-purpose register. Accordingly, when a predeterminedcondition is satisfied during execution of a specific task, by settingthe condition flag in the general-purpose register on the basis of anormal instruction, the condition-added sampling function can beimplemented by software.

According to a sixth aspect, when an instruction of an input processingsystem is executed, the CPU is equipped with a twice coincidence filterfunction of storing a previous input terminal state and a present inputterminal state into the general-purpose register and permittingexecution of the instruction of the input processing system when boththe values match each other. Here, “the instruction of the inputprocessing system” means the “input capture instruction”, “samplingcompare instruction”, “input compare set instruction”, “condition-addedsampling instruction” according to the second to fifth aspects.Accordingly, the input processing system instruction can be executed atthe stage that it is confirmed that the state of the input signal ordata becomes stable.

According to a seventh aspect, the CPU is designed so that it isselectable in accordance with the bit in the general-purpose registerwhether it is possible or not to execute the twice coincidence filterfunction. Therefore, whether it is necessary or not to use the filtermultifunction concerned can be selected in accordance with the user'sapplication.

According to an eighth aspect, when an output compare instruction isexecuted, CPU achieves a compare period value and an output levelindicating condition set in the general-purpose register. Furthermore,as in the case of the sampling compare instruction, the data achieved byaccumulating and adding the compare period and the compare value arestored in the general-purpose register, and if the compare value and thetimer counter value match each other, the indicated level is output fromthe output terminal, and the satisfaction flag is stored in thegeneral-purpose register. Accordingly, by executing the output compareinstruction after the compare period value is set in the general-purposeregister on the basis of a normal instruction in advance, the outputcompare function can be implemented by software.

According to a ninth aspect, when a condition-added output instructionis executed, the CPU achieves an output level indicating condition setin the general-purpose register. Furthermore, the CPU judges whether acondition flag is set in the general-purpose register. If the setting ofthe condition flag is recognized, the level corresponding to theindicated condition is output to the output terminal, and also thesatisfaction flag is stored in the general-purpose register.Accordingly, when a predetermined condition is satisfied while aspecific task is executed after the output level indicating condition isset in the general-purpose register by the normal instruction inadvance, by setting the condition flag in the general-purpose registeron the basis of the normal instruction, the condition-added outputfunction can be implemented by software.

It is also a concern of the present disclosure to provide an instructioncode encoding system that can allocate plural instructions to aninstruction code in which all operands other than an operation code areset as parameters, and a CPU having an instruction decoder adopting theencoding system.

According to an instruction code encoding system of a tenth aspect, whenan operation target indicated by plural operands in an instruction codeis a combination in which a result achieved by executing an instructionindicated by an operation code does not vary, the processingcorresponding to an instruction different from the instruction isexecuted. That is, in some combination of the instruction content of anoperation code and a target executing the instruction concerned, theremay occur such a case that the execution result of the instruction doesnot vary and the same situation as execution of NOP (No Operation)instruction occurs.

Accordingly, in such a case that indication of plural operands in aninstruction code induces the result described above, the combination isa practically unusable combination, and thus even when an instructionwhich is different in execution style from the original instruction isexecuted, the performance is not degraded and thus there is no problem.Accordingly, plural instructions can be allocated to an instruction codein which all fields other than the operation code are set as parameters.

According to an instruction code encoding system of an eleventh aspect,in a case where the instruction code has two operands and theinstruction indicated by the operation code executes an operation foroperation targets indicated by the two operands, when the operationtargets indicated by the two operands are identical to each other andthe execution result of the operation on these operation targets doesnot vary, the operation is executed between the operation targets andanother predetermined operation target.

That is, the instructions for executing the instruction on targetsindicated by two operands contains an instruction in which the executionresult does not vary if they are the same target. Accordingly, when theindication of the two operands is set to the same target in such aninstruction, another instruction can be allocated.

According to CPU of a twelfth aspect, the instruction decoder adopts theinstruction code encoding system of the tenth or eleventh aspect,whereby more diverse instructions can be executed without increasing thenumber of prepared instruction sets.

BRIEF DESCRIPTION OF THE DRAWINGS

The above and other objects, features and advantages will become moreapparent from the following detailed description made with reference tothe accompanying drawings. In the drawings:

FIG. 1 is a functional block showing the construction of a microcomputeraccording to a preferred embodiment;

FIG. 2 is a timing chart showing a state where the microcomputerexecutes time-divisional parallel processing on A-task and L-task;

FIG. 3A is a set state of each bit in a general-purpose register for aninput capture instruction, FIG. 3B shows the content of processingexecuted in an executing stage of pipeline processing which isrepresented by C language, and FIG. 3C is a timing chart showing anexample of an executing mode;

FIGS. 4A-4C correspond to FIGS. 3A-3C for a sampling compareinstruction;

FIGS. 5A-5C correspond to FIGS. 3A-3C for an output compare instruction;

FIGS. 6A-6C correspond to FIGS. 3A-3C for an input compare setinstruction;

FIGS. 7A-7C correspond to FIGS. 3A-3C for a condition-added samplinginstruction;

FIGS. 8A-8C correspond to FIGS. 3A-3C for a condition-added outputinstruction;

FIG. 9 is a diagram showing a CSMA/CD communication system when thefunction at a reception side is implemented by a peripheral functioninstruction;

FIG. 10 corresponds to FIG. 9 for the function at a transmission side;

FIG. 11 corresponds to FIG. 9 for an event timer function;

FIG. 12 corresponds to FIG. 9 for a port sampling function;

FIG. 13 corresponds to FIG. 9 for a clock synchronous serialcommunication function;

FIG. 14 corresponds to FIG. 9 for a UART communication function;

FIG. 15 corresponds to FIG. 9 when a bit synchronous function to beexecuted at the communication start time of LIN;

FIGS. 16A to 16C are diagrams showing a content when an instruction codecoded on the basis of an instruction encoding system of a preferredembodiment is decoded and executed by CPU;

FIG. 17 is a flowchart showing the processing content of a hardwarelogic when an instruction fetched by the instruction decoder of CPU isdecoded;

FIG. 18 is a diagram showing a case where CPU executes a program using abmov instruction (bit_s=bit_q);

FIG. 19 is a functional block diagram showing an internal constructionof the CPU; and

FIG. 20 is a diagram showing the construction of an instruction codeaccording to a related art.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

A preferred embodiment will be described hereunder with reference to theaccompanying drawings.

FIG. 1 is a functional block diagram showing the construction of amicrocomputer 10. The microcomputer 10 is equipped with a CPU 11, aprogram memory 12 constructed by a ROM, a data memory 13 constructed byRAM, an I/O block 14 (input/output pin), a timing generator (not shown)for generating a CPU switching signal (clock signal) described later, adata bus 15 for transmitting/receiving data, an address bus 16 fortransmitting/receiving an address signal, and control buses 17, 18 fortransmitting/receiving a read signal and a write signal.

CPU 11 is equipped with two address registers 19, 20 and two operatingregisters 21, 22 to time-divisionally executing pipeline processing ontwo kinds of tasks (L-task, A-task) in parallel, and alternatelyswitching the address registers 19, 20 and the operating registers 21,22 on the basis of the CPU switching signal, whereby the CPU 11functions apparently so that two CPUs are alternately switched andoperated.

In this case, one address register 19 and one operating register 21serve as registers for CPU0 (for L-task), and the other address register20 and the other operating register 22 serve as registers for CPU1 (forA-task). The value of a program counter 23 (an address of an instructionto be next fetched) is renewed in accordance with the switching betweenthe address registers 19, 20, and the address signals for CPU0 (forL-task) and CPU1 (for A-task) are alternately output from the programcounter 23 to the program memory 12.

Furthermore, CPU 11 contains therein an error detecting circuit 24 as anerror detecting unit for identifying the type of A-task to which aninstruction read out from the program memory 12 belongs and detecting anerror thereof, and an instruction decoder/instruction sequencer 25 fordecoding (deciphering) an instruction passed through the error detectingcircuit 24. In accordance with the content of the instruction decoded bythe instruction decoder/instruction sequencer (hereinafter referred toas instruction decoder) 25, a calculating operation is executed in anoperating unit 26 (ALU) by using operating registers 21, 22 inaccordance with the content of an instruction decoded by the instructiondecoder/instruction sequencer, or a read signal or write signal isoutput to the control buses 17, 18.

The program memory 12 is equipped with a program area 27 for CPU0 (forL-task), a program area 28 for CPU1 (for A-task), and a table immediatedata area 29 therein. In this case, the L-task stored in the programarea 27 for CPU0 is constructed by a fix-looped program in which abranch instruction having a risk that it falls into a program runawaystate is prohibited. Accordingly, at the execution time of the programof the L-task, the execution is started from address 0 by 2-byteinstruction access, and the instructions are successively executed likeaddress 2, address 4, address 6, . . . . Thereafter, the program counter23 overflows when the address reaches a predetermined address, andreturns to the address 0. Thereafter, the instruction execution isrepeated in the above address order. In this L-task, all theinstructions are fixed to one-word (two-byte) instructions.

The L-task (specific task) is suitable to execute the sequence controlprocessing, and the program thereof contains an A-task runawaymonitoring routine and a backup sequence routine for satisfying failsafe of the system. Furthermore, the L-task is also equipped with afunction as a timer based on a fix-loop operation. For example, when anincrement instruction or decrement instruction is executed and the countvalue thereof reaches a predetermined set value, fixed time processingequivalent to timer interrupt can be performed by generating interruptin the processing of the A-task.

On the other hand, the A-task is permitted to contain a branchinstruction which is prohibited to the L-task, and thus it is suitablefor complicated analysis processing/numerical calculation. As in thecase of the L-task, all the instructions are also fixed to one-wordinstructions in the A-task. Both of an operation code and an operand(address) are allocated in one word for the A-task and the L-task.

Next, a pipeline control system adopted in the microcomputer thusconstructed will be described with reference to FIG. 2. The pipeline isconstructed as a three-stage pipeline comprising respective stages ofinstruction fetch, instruction decode and instruction execution, forexample, and designed so that all the instructions can be processed bythe three-stage pipeline with no delay. Each stage is executed by onecycle, and one instruction is executed by three cycles. However,parallel processing is executed on these three instructions by thethree-stage pipeline, whereby it is apparently equivalent to a system inwhich one instruction is executed by one cycle.

The time of one cycle (each stage) is defined by a CPU switching signal(clock signal). With respect to the CPU switching signal, a low-leveltime Tlo and a high-level time Thi are equal to each other. Theinstruction fetch of CPU0 (L-task) is executed for the low-level period,and the instruction fetch of CPU1 (A-task) is executed for thehigh-level period, whereby both the programs of CPU0 (L-task) and CPU1(A-task) are subjected to the pipeline processing in parallel at thetime-divisional ratio of 1:1.

Furthermore, when CPU1 fetches the branch instruction contained in theprogram of the A-task, it is constructed so as to set a branchdestination address at an instruction decode stage in order to fetch theinstruction of the branch designation address at the next instructionfetch stage of the A-task containing the branch instruction concerned.FIG. 2 shows the processing timing when an instruction at an address(Y+1) of CPU1 is a branch instruction (JMP).

CPU 11 is equipped with plural address registers 19, 20 for successivelysetting an instruction address different to the program counter 23, andplural operating registers (instruction registers) 21, 22 forsuccessively setting the instruction decoded by the instruction decoder25 to the operating unit 26, and the plural programs 27, 28 stored inthe program memory 12 can be subjected to the pipeline processing bysuccessively switching the plural address registers 19, 20 and theplural operating registers 21, 22.

Furthermore, a “peripheral function instruction” described later isprepared as an instruction set of CPU 11. The “peripheral functioninstruction” is an instruction prepared so that the processingimplemented by hardware constructed at the outside of CPU 11 can beprocessed in a software style in the L-task by CPU 11. The instructiondecoder 25 and the operating unit 26 are constructed so that theperipheral function instruction is implemented at one cycle at theexecution stage of the pipeline processing.

For example, when a load instruction is executed on the peripheralcircuit of CPU 11, data read out through the data bus 15 is normallystored in the general-purpose register 30. The general-purpose register30 of this embodiment is constructed so that when the instructiondecoder 25 executes a decode operation on an instruction and as a resultthe instruction concerned is “peripheral function instruction”, theinput signal level of the input terminal 31 can be stored in some bitsor the signal corresponding to data set in some bits can be outputthrough the output terminal 32. Furthermore, transmission of data can beperformed between the general-purpose register 30 and the programcounter 23. Actually, plural general-purpose registers 30, plural inputterminals 31 and plural output terminals 32 exist, however, theseelements are illustrated in a single style in FIG. 1 for convenience ofillustration.

Next, the action of this embodiment will be described with reference toFIGS. 3A to 15.

FIGS. 3A to 8A show set states of each bit in the general-purposeregister when CPU 11 executes the peripheral function instruction, FIGS.3B to 8B show the contents of processing executed at one cycle (byhardware) in the execution stage of the pipeline processing in theinstruction decoder 25 or the operating unit 26, the contents beingrepresented by C language, and FIGS. 3C to 8C are timing charts showingexamples of the execution mode.

<Input Capture Instruction>

FIG. 3B shows the content of the input capture instruction. The inputcapture function serves to read in the count value of a free run counterat a timing at which a specific trigger signal is given. For example, itis used when the time between signal edges of an input terminal ismeasured or for mere edge detection. In this embodiment, when CPU 11executes an input capture instruction described in the L-task, by usingthe count value of the program counter 23 as a timer counter, it isprocessed in a software mode in CPU 11.

Here, “processing in a software mode” means the processing that iscompleted inside CPU 11 in comparison with processing executed by usinghardware provided at the outside of CPU 11. That is, the term “softwaremode” is used to refer to operations based on internal logics of CPU 11.

As shown in FIG. 3A, when the input capture instruction is executed,each bit of a register Rm which is one type general-purpose register 30is allocated as follows.

Bit

15: present input terminal state (level)

14: previous input terminal state (level)

13: Sampling value (level) of input terminal

11: twice-coincidence filter allow/prohibition

10, 9: signal edge indication of input terminal

8: input capture satisfaction flag

7 to 0: capture value

The twice-coincidence filter allowance/prohibition in bit 11 and thesignal edge indication of the input terminal in bit 10, 9 are set in theregister Rm in advance by a load instruction described at the A-taskside, and the register Rm is indicated by an operand in the inputcapture instruction.

With respect to the input capture instruction, the processing contentshown in FIG. 3B is executed in the execution stage. The procedure shownin FIG. 3B is not executed step by step, but when the input captureinstruction is executed, these processing is executed at one cycle bythe instruction decoder 25 or the logic of the operating unit 26.

That is, when the twice-coincidence filter allowance is set in the bit13, the exclusive OR of the bits 15, 14 is satisfied, and if both arenon-coincident with each other, the content of the bit 15 is transferredto the bit 14. Even when both are coincident with each other, thecontent of the bit 15 at that time is likewise transferred to the bit14. When filter prohibition is set, the content of the bit 15 istransferred to the bit 14 without executing the first non-coincidencejudgment. Then, the edge judgment of the input terminal 31 is executed.

In the edge judgment, the bit 15 which is the level of the inputterminal 31 at the present time is compared with the bit 13 in which thelevel of the input terminal 31 when the same instruction is previouslyexecuted is stored as a sampling value. If both are coincident with eachother, there is no variation in input level and thus no edge isdetected. Therefore, the content of the bit 15 is transferred to the bit13, and the processing is finished.

On the other hand, if both the bits 15, 13 are non-coincident with eachother, the level of the input terminal 31 is varied, and the edge isdetected. In this case, it is judged that the edge condition (rising,falling, any edge) indicated by the bits 10, 9 is satisfied. If thecondition concerned is satisfied, the value of the program counter 23 isstored in the bit 7:0 of the register Rm, the satisfaction flag is putup in bit 8, and then the processing is finished. The indication of eachinput terminal 31 may be changeable by another general-purposeinstruction even when it is fixed at default.

If the input capture function is implemented by providing a circuitexterior to the CPU 11, such a following circuit would generallyrequire:

-   (1) Free run timer;-   (2) Capture register for storing the count value of the free run    timer; and-   (3) Control register for indicating an edge as a trigger and    selecting the presence or absence of the twice-coincidence filter.

On the other hand, in this embodiment, (1) is supported by the programcounter 23, and (2) and (3) are supported by the register Rm, wherebythe input capture function is implemented by CPU 11 alone as hardware.

<Sampling Compare Instruction>

FIG. 4 shows the content of the sampling compare instruction. Thesampling compare function samples the level of the input terminal 31every time the indicated sampling period elapses. In this case, thecount value of the program counter 23 is used as a timer counter.

As shown in FIG. 4A, when the sampling compare instruction is executed,each bit of the registers Rm, Rn in the general-purpose register 30 isallocated as follows.

Register Rm

bit

15: present input terminal state (level)

14: previous input terminal state (level)

13: sampling value (level) of input terminal

12: sampling result (in the case of 1 bit)

11: twice-coincidence filter allowance/prohibition

10, 9: indication of sampling

8: sampling compare satisfaction flag

7 to 0: compare value

Register Rn

bit

15 to 8: sampling result (in the case of 1 bite)

7 to 0: compare period

With respect to the sampling compare instruction, the processing contentas shown in FIG. 4B is executed. In the processing of thetwice-coincidence filter, if the bits 15, 14 are non-coincident witheach other, the content of the bit 15 is transferred to the bit 14. Ifboth are coincident with each other or the filter prohibition is set,the content of the bit 15 is transferred to each of the bits 14, 13.When the count value of the program counter 23 is above the bit 7:0 ofthe register Rm, that is, the compare period Δt elapses, the bit 7:0 ofthe register Rn is added to the bit 7:0 of the register Rm, and the nextcompare value is set. Then, the satisfaction flag is put up in the bit8, and the sampling is executed in conformity with a mode indicated bythe bits 10, 9 of the register Rm. The sampling indication is set asfollows, for example.

Bit 10, 9 sampling mode 00 1 bit 01 default 10 1 byte (left shift) 11 1byte (right shift)

The left shift corresponds to MSB first, and the bit 13 of the registerRm is stored from the bit 8 side of the register Rn while leftwardshifting bit by bit. The right shift corresponds to LSB first, and thebit 13 of the register Rm is stored from the bit 15 side of the registerRn while rightward shifting the register Rn bit by bit.

<Output Compare Instruction>

FIGS. 5A-5B show the content of the output compare instruction. Theoutput compare function outputs a signal from the output terminal everytime an indicated compare period elapses. For example, it is used tooutput a PWM signal and to output a signal interlockingly with a sleeptimer for measuring a shift time when the microcomputer 10 is shifted toa sleep mode. In this case, the count value of the program counter 23 isused as a timer counter.

As shown in FIG. 5A, when the output compare instruction is executed,each bit of the registers Rm, Rn in the general-purpose register 30 isallocated as follows.

Register Rm

bit

15: Level setting of output terminal

11 to 9: Indication of output level

8: output compare satisfaction flag

7 to 0: compare value

Register Rn

bit

15 to 8: output data (in the case of 1 byte)

7 to 0: compare period

The output indication and the compare period are set by otherinstructions before the output compare instruction is executed. Theoutput compare instruction is executed as follows. First, the countvalue of the program counter 23 is above the bit 7:0 of the register Rm,that is, the compare period Δt elapses, the bit 7:0 of the register Rnis added to the bit 7:0 of the register Rm and the next compare value isset. Then, the satisfaction flag is put up in the bit 8, and the outputis executed in accordance with the mode indicated by the bits 11 to 9 ofthe register Rm. The indication of the output level is set as follows,for example.

Bit 11 to 9 sampling mode 000 no output 001 output “L” 010 output “H”011 inversion of present level 100 no output 101 no output 110 output 1byte (right shift) 111 output 1 byte (left shift)

The right shift of the 1 byte output corresponds to LSB first, and whenthe bit 8 of the register Rn is stored in the bit 15 of the register Rm,the bits 15 to 8 of the register Rn are rightward shifted by one bit.Furthermore, the left shift of the 1 byte output corresponds to MSBfirst, and when the bit 15 of the register Rn is stored in the bit 15 ofthe register Rm, the bits 15 to 8 of the register Rn are leftwardshifted by one bit.

<Input Compare Set Instruction>

FIGS. 6A-6B show the content of the input compare set instruction. Theinput compare set function sets the compare value when the indicatededge of the input terminal 31 is detected. In this case, the count valueof the program counter 23 is also used as a timer counter. Theprocessing of the twice-coincidence filter is the same as the inputcapture instruction.

As shown in FIG. 6A, when the input compare set instruction is executed,each bit of the registers Rm, Rn in the general-purpose register 30 isallocated as follows.

Register Rm

Bit

15: present input terminal state (level)

14: previous input terminal state (level)

13: Sampling value (level) of input terminal

11: Twice-coincidence filter allowance/prohibition

10, 9: Indication of edge

8: Input compare set satisfaction flag

7 to 0: compare set value

Register Rn

Bit

7 to 0: compare value

The indication of edge and the compare set value are set by other normalinstructions before the input compare set instruction is executed. Theinput compare set instruction is executed as follows. The processing ofthe twice-coincidence filter is the same as the input captureinstruction or the like, and thus the description thereof is omitted.First, the content of the bit 15 is transferred to the bit 14. Then, theedge judgment of the input terminal 31 is executed as in the case of theinput capture instruction. When the edge is detected and the edgecondition is satisfied, the bit 7:0 of the register Rm is added to thecount value of the program counter 23, and the addition result is set inthe bit 7:0 of the register Rn. Then, the satisfaction flag is put up inthe bit 8. As shown in FIG. 6C, the input compare set instruction isused, for example when the compare set value Δt is set at the time whenthe falling edge of a signal is detected or the like.

<Condition-Added Sampling Instruction>

FIGS. 7A-7B show the content of the condition-added samplinginstruction. The condition-added sampling function samples the level ofthe input terminal 31 when a condition flag is set as a result of someprocessing. As shown in FIG. 7A, when the condition-added samplinginstruction is executed, each bit of the register Rm is allocated asfollows.

Bit

15: Present input terminal state (level)

14: previous input terminal state

13: sampling value (level) of input terminal

12: sampling result (1 bit)

11: twice-coincidence filter allowance/prohibition

10, 9: indication of sampling

8: condition-added sampling satisfaction flag

7 to 0: sampling result (1 bit)

Furthermore, the condition flag is stored in the bit 8 of the registerRn. As shown in FIG. 7B, when the condition flag is set, thetwice-coincidence filter processing and also the sampling processing areexecuted, and if no condition flag is set, only the twice-coincidencefilter processing is executed. In any case, the filter processing islikewise executed when a filter allowance flag is set.

With respect to the sampling processing, the satisfaction flag is put upin the bit 8 of the register Rm, the sampling is executed in accordancewith the indication of the sampling as in the case of the samplingcompare instruction. However, in the case of 1 byte sampling, thesampling result is stored in the bits 7 to 0 of the register Rm. FIG. 7Cshows a case where the sampling is executed under the condition thatsome falling edge of the input terminal 31 is detected.

<Condition-Added Output Instruction>

FIGS. 8A-8B show the content of the condition-added output instruction.The condition-added output function outputs the indicated level from theoutput terminal. As shown in FIG. 8A, when the condition-added outputinstruction is executed, each bit of the register Rm is allocated asfollows.

Register Rm

bit

15: level setting of output terminal

11 to 9: indication of output level

8: output compare satisfaction flag

7 to 0: output value (1 byte)

The condition flag is stored in the bit 8 of the register Rn. When thecondition flag is set in the bit 8 of the register Rn, thecondition-added output instruction is executed as the processing contentas shown in FIG. 8B. First, when the satisfaction flag is put up in thebit 8 of the register Rm, the output is executed from the outputterminal 32 in accordance with the same output indication as the outputcompare instruction. However, in the case of 1 byte output, data set inthe bits 7 to 0 are given to the bit 15 of the register Rm while beingshifted bit by bit. FIG. 8C shows a case where inverted output, nooutput, inverted output are executed under a condition that a risingedge of the input terminal 31 is detected.

[Case Study: CSMA/CD, Reception]

Next, FIGS. 9 to 15 shows an example of implementing a specific functionby using the peripheral function instruction (peripheral instruction)described above. FIG. 9 shows a case where the function at the receptionside is implemented for the CSMA/CD system which is one of communicationsystems used for LAN. The functions to be implemented are as follows.

-   (1) When the falling of a reception data Rx is detected, the    reception data Rx is sampled after Δt2 from that time point.-   (2) If no edge is detected as a sampling result of (1), the    reception data Rx is further sampled after Δt1 (1 bit period), and    if an edge is detected (collision detection), the reception data Rx    is further sampled after Δt2 (bit synchronization).

The bit synchronization is executed as follows.

-   Previous reception data: 0→synchronized at the falling edge-   Previous reception data: 1→synchronized at rising edge-   Under transmission of dominant “0”→synchronized at falling edge-   Under transmission of dominant “1”→synchronized at rising edge-   The above functions are implemented by    <Input Compare Set Instruction>-   (1) when the edge of the reception data Rx is detected, the sampling    timing is changed to Δt2.    <Sampling Compare Instruction>-   (2) The reception data Rx is sampled every Δt1.    [Case Study: CSMA/CD, Transmission]

FIG. 10 shows a diagram showing implementation of the function at thetransmission side in the CSMA/CD system. The content of the function isas follows.

-   (1) Transmission data are output every fixed period (Δt1).-   (2) Transmission data are output when reception data level varies    and an edge is detected.    These functions can be implemented by the following peripheral    function instructions:    <Output Compare Instruction>-   (1) Transmission data are output from the output terminal every    fixed period (Δt1).    <Input Compare Set Instruction>-   (2a) The edge of the reception data Rx is detected.

In this case, when the satisfaction flag is set in the bit 8 of theregister Rm as an execution result of the instruction concerned, thecontent of the bit 8 is transferred to the bit 8 of the register Rn.

<Condition-Added Output Instruction>

-   (2b) Transmission data are output from the output terminal by    detecting the edge.    [Case Study: Event Timer]

FIG. 11 shows implementation of an event timer function. This functionis

-   (1) detecting a signal edge at the input terminal 31, and-   (2) sampling the level of the input terminal 31 after Δt from the    edge detection, and can be implemented by    <Input Compare Set Instruction>-   (1) detecting the signal edge of the input terminal 31 and setting    the compare period Δt, and    <Sampling Compare Instruction>-   (2) sampling the level of the input terminal 31 at the time when the    compare period Δt elapses.    [Case Study: Port Sampling]

FIG. 12 shows a port sampling function. This function is

-   (1) outputting a signal from the output terminal at any timing, and-   (2) sampling the input terminal 31 after Δt when the signal edge of    the output terminal is detected. The sampling port can be selected    from “32”, for example. These functions can be implemented by    <Output Compare Instruction>-   (1) outputting a signal from the output terminal 32 (PSMOUT) when    the program counter 23 is coincident with a predetermined count    value, and    <Input Compare Set Instruction>-   (2a) setting the compare period by detecting the edge of the output    terminal 32, and-   (2b) sampling the input terminal 31 when the program counter 23 is    coincident with the compare period.    [Case Study: Clock Synchronous Serial]

FIG. 13 shows a case where a clock synchronous serial communicationfunction is implemented. The communication function is as follows.

-   (1) A signal is output (transmitted) from the output terminal 32    (SOUT) by detecting the falling edge of a serial clock SCLK, and-   (2) The input terminal 31 (SIN) is sampled (received) by detecting    the rising edge of SCLK, and there are other functions such as    selection of an external clock/an internal clock, LSB/MSB first,    clock polarity, detection of an overrun error, etc.

The functions (1), (2) are implemented by the peripheral functioninstruction as follow.

<Input Capture Instruction>

-   (1a) Detecting the edge (falling, rising) of SCLK    <Condition-Added Output Instruction>-   (1b) Outputting transmission data from the output terminal 32 by    detecting the edge (falling)    <Condition-Added Sampling Instruction>-   (2) Sampling the input terminal 31 by detecting the edge (rising)    [Case Study: UART]

FIG. 14 shows a case where a UART communication function is implemented.This communication function executes

-   (1) Sampling the input terminal 31 after Δt from the edge detection    (falling, start bit detection)-   (2) thereafter, sampling (receiving) the input terminal 31 every    (Δt×2)-   (3) or outputting data from the output terminal 32 every (Δt×2), and    detection of overrun error, framing error, parity error, etc.    The functions of (1) to (3) are implemented by the peripheral    function instruction as follows.    <Input Compare Set Instruction>-   (1) Detecting the signal edge (rising) of the terminal and setting    the compare period Δt    <Sampling Compare Instruction>-   (2) Sampling the input terminal 31 when the program counter is    coincident    <Output Compare Instruction>-   (3) Outputting data from the output terminal 32 when the program    counter is coincident (period: Δt×2)    [Case Study: LIN]

FIG. 15 shows a case where a bit synchronous function executed at thecommunication start time is implemented in LIN which is one type ofin-vehicle LAN. This function is as follows.

-   (1) Recognizing start of communication when it is measured that the    low level period of SYNCH BREAK reaches Δt-   (2) Measuring the clock period (between falling edges) Δt2 to be    transmitted in SYNCH FIELD, and adjusting a bit rate (measuring over    four periods and divided by “8”)

The functions (1) and (2) are implemented by the peripheral functioninstruction as follows.

<Input Capture Instruction>

The edge of the input terminal 31 is detected to achieve the count valueof the program counter 23. The other processing can be implemented bythe normal instruction.

That is, as described above, plural communication functions different insystem can be implemented by software. Therefore, it is unnecessary tomount communication interface LSI in the microcomputer 10 in connectionwith each case where each communication function is implemented.Accordingly, the general versatility of the microcomputer 10 can beenhanced.

As described above, according to the embodiment described above, CPU 11of the microcomputer 10 is designed so that the peripheral functioninstruction described in the L-task can be executed as one instruction.CPU 11 achieves information needed to execute the peripheral functioninstruction from the general-purpose register 30 indicated by anoperand, and also stores the information concerning the execution resultof the instruction concerned into the general-purpose register 30.Accordingly, the description of the program for implementing theperipheral function by software can be remarkably simplified, so thatthe program size can be reduced. Furthermore, the bit of thegeneral-purpose register 30 can be operated by an instruction which isnormally prepared in CPU 11, and thus it is unnecessary to separatelyprepare for a special instruction such as a prefix instruction in orderto execute the peripheral function instruction.

Furthermore, when the input capture instruction is executed, CPU 11achieves the edge indicating information of the input terminal 31 as acondition for achieving the timer value from the general-purposeregister 30, judges on the basis of the state information of the inputterminal 31 stored in the general-purpose register 30 whether theachieving condition is satisfied or not, stores as a capture value thevalue of the program counter 23 at the time when the condition concernedis satisfied, and also stores the satisfaction flag. Accordingly, byexecuting the input capture instruction after the edge indicatinginformation is set in the general-purpose register 30 by the normalinstruction in advance, the input capture function can be implemented bysoftware.

Furthermore, when the sampling compare instruction is executed, CPU 11achieves the compare period value set in the general-purpose resister30, and stores the data achieved by accumulating and adding the compareperiod value every sampling timing as a compare value in thegeneral-purpose register 30. When the compare value and the value of theprogram counter 23 are coincident, the sampling result and thesatisfaction flag are stored into the general-purpose register 30.Accordingly, by executing the sampling compare instruction after thecompare period value is set in the general-purpose register 30 by thenormal instruction in advance, the sampling compare function can beimplemented by software.

Furthermore, when the input compare set instruction is executed, CPU 11achieves the compare period value set in the general-purpose register 30and the edge indicating information of the input terminal 31 which is acompare set condition, and if the condition concerned is satisfied, thevalue of the program counter 23 at that time point is added with thecompare period value. The addition result is stored as the compare valuein the general-purpose register 30, and also the satisfaction flag isstored. Accordingly, the compare period value and the edge indicatinginformation are set in the general-purpose register 30 by the normalinstruction in advance, and then the input compare set instruction isexecuted, whereby the input compare set function can be implemented bysoftware.

When the condition-added sampling instruction is executed, CPU 11 judgeswhether the condition flag is set in the general-purpose register 30. Ifthe setting of the condition flag is recognized, CPU 11 stores thesampling result and the satisfaction flag into the general-purposeregister 30. Accordingly, when a predetermined condition is satisfiedwhile the L-task is executed, the condition flag is set in thegeneral-purpose register 30 by the normal instruction, whereby thecondition-added sampling function can be implemented by software.

Furthermore, when CPU 11 executes the input capture instruction, thesampling compare instruction, the input compare set instruction or thecondition-added sampling instruction, which are the instructions of theinput processing system, CPU 11 is equipped with the twice-coincidencefilter function of storing the previous and present states of the inputterminal 31 into the general-purpose register 30 and allowing executionof the input processing system instruction when both the values arecoincident with each other. Therefore, the input processing systeminstruction is executed at the stage whether it is confirmed that thestate of the input signal or data is stabilized. CPU 11 is designed sothat execution or non-execution of the twice-coincidence filter functioncan be selected in accordance with the setting of the bit in thegeneral-purpose register 30. Therefore, the necessity or non-necessityof the filter function can be selected in accordance with the user'sapplication.

Furthermore, when the output compare instruction is executed, CPU 11achieves the compare period value and the output level indicatingcondition set in the general-purpose register 30, and the compare valueis stored in the general-purpose register 30 as in the case of thesampling compare instruction. If the compare value and the value of theprogram counter 23 are coincident with each other, the indicated levelis output from the output terminal, and also the satisfaction flag isstored in the general-purpose register 30. Accordingly, the compareperiod value is set in the general-purpose register 30 in advance by thenormal instruction, and then the output compare instruction is executed,whereby the output compare function can be implemented by software.

Still furthermore, when the condition-added output instruction isexecuted, CPU 11 achieves the output level indicating condition set inthe general-purpose register 30, and judges whether the condition flagis set in the general-purpose register 30. If the setting of thecondition flag is recognized, CPU 11 outputs the level corresponding tothe indicated condition to the output terminal, and also stores thesatisfaction flag into the general-purpose register 30. Accordingly,when a predetermined condition is satisfied while the specific task isexecuted after the output level indicating condition is set in thegeneral-purpose register 30 in advance by the normal instruction, thecondition-added output function can be implemented by the software ifthe condition flag is set in the general-purpose register 30 by thenormal instruction.

The present invention is not limited to the embodiments described aboveand shown in the figures, and the following modifications may be made.

The function of setting execution or non-execution of thetwice-coincidence filter may be provided as occasion demands, and thetwice-coincidence filter function itself may be provide as occasiondemands.

The number of tasks to be processing time-divisionally and in parallelby CPU may be equal to three or more.

With respect to the peripheral function instruction, a necessaryperipheral function instruction may be suitably selected and implementedin accordance with the specification of the microcomputer.

Another preferred embodiment will be described with reference to FIGS.16A to 20. FIG. 19 is a functional block diagram showing an internalconstruction of a CPU which is associated with the subject matter of thepreferred embodiment. CPU 1 is equipped with a controller 2, anarithmetic logic unit (ALU) 3, a register portion 4, etc. The controller2 comprises a decoder (instruction decoder) 5 for decoding aninstruction fetched from an external program memory (not shown), and asequencer 6 for controlling instruction execution in the arithmeticlogic unit 3 in accordance with a decoding result.

The register portion 4 comprises plural status registers, a controlregister, a general-purpose register, logics for carrying out datawriting and reading operations on these registers, etc. The arithmeticlogic unit 3 executes an operation on data read out from the registersof the register portion 4 and stores the operation result into theregisters.

The construction of CPU 1 is not apparently different from theconstruction of general CPU, however, it is characterized by theprocessing executed when the instruction fetched by the decoder 5 isdecoded. The content of the decode processing is shown in the flowchartof FIG. 17, however, this flowchart is the content executed by theinternal hardware logic in the decoder 5.

Next, the action of this embodiment will be described with reference toFIGS. 16A to 18. FIGS. 16A to 16C show a content when the CPU decodesand executes an instruction code coded on the basis of the encodingsystem of the present invention. FIG. 16A shows a bit transferinstruction:bmov whose code size is equal to 16 bits, and four operandseach of which comprises four bits are allocated as follows.

Bit content 15 to 12 operation code: ope 11 to 8 operand source bit:bit_s (operation target)  7 to 4 operand register: rn  3 to 0 operanddestination bit: bit_q (operation target)

As shown in FIG. 16B, the bmov instruction normally executes thearithmetic processing of transferring the content of a source bit (forexample, eight bit) to a destination bit (for example, third bit) in ageneral-purpose register rn indicated as an operand, that is, 1-bitoperation (when bit_s≠bit_q). In this case, the decode operation of thedecoder 5 corresponds to S1→S2→S5 in the flowchart shown in FIG. 17.

Accordingly, if the source bit and the destination bit are set to beidentical to each other in the bmov instruction (when bit_s=bit_q), thesame data are overwritten on the same bit as when the above arithmeticprocessing is executed, and thus the execution result does not vary.That is, the same result as when an NOP instruction is executed isachieved.

Therefore, in this embodiment, as shown in FIG. 16C, the decoder 5 ofCPU 1 is designed so that the processing corresponding to an instructiondifferent from the bmov instruction is executed when the source bit andthe destination bit are set to be identical to each other in the bmovinstruction.

That is, in FIG. 16C, each of the source bit and the destination bit areindicated to the third bit. In this case, the decoder 5 executes theprocessing of transferring the content of a carry flag [C] (anotheroperation target whose operation result is carry or borrow) disposed inthe condition code register of the register portion 4 (may beconstructed as a part of CC register, status register) to thedestination bit of the register rn. In the flowchart of FIG. 17, thisdecode operation corresponds to step S1→S2→S3. When the instruction ofthe decode target is an instruction other than the bmov instruction, itcorresponds to step S1→S6.

Another flag [N] in the CC register means “negative” (the uppermost bitis equal to “1” from the execution result of the instruction), flag [Z]means “zero” (the execution result of the instruction is zero) and flag[V] means “overflow” (the arithmetic result is a complement of 2 and itcannot be expressed).

Here, FIG. 18 shows a specific example when CPU 1 executes a programusing the above bmov instruction (bit_s=bit_q), and also shows that thecontent of the fifth bit of the general-purpose register rm istransferred to the third bit of the register rn. CPU 1 has a btbeq (bittest branch equal) instruction as one of instruction sets, and thisbtbeq instruction is assumed to be an instruction of transferring thecontent of any bit of any general-purpose indicated as an operand to thecarry flag of the CC register.

In this case, the btbeq instruction is first executed to transfer thecontent of the fifth bit of the general-purpose register rm to the carryflag of the CC register, and then the bmov instruction (bit_s=bit_q=3)is executed by the same indication as shown in FIG. 16A, whereby thecontent of the carry flag can be transferred to the third bit of theregister rn.

As described above, according to this embodiment, when operation targetsindicated by plural operands in an instruction code, the decoder 5 ofCPU 1 are set to a combination in which the result achieved by executingthe instruction indicated by an operation code does not vary, thedecoder 5 of CPU 1 executes processing corresponding to an instructiondifferent from the above instruction. Specifically, in the bmovinstruction of transferring the content of the source bit in theindicated general-purpose register rn to the destination bit, when bothare indicated to the same bit, the content of the carry flag [C]disposed in the CC register is transferred to the destination bit of theregister rn.

Accordingly, plural instructions can be also allocated to an instructioncode in which all the operands other than the operation code are set asparameter. CPU 1 can execute more diverse instructions withoutincreasing the number of instruction sets prepared in advance.

The present invention is not limited to only the embodiments describedabove or shown in the figures, and the following modifications may bemade.

In the case of (bit_s=bit_q), the content of an instruction executed inplace of the original 1-bit operation instruction is not limited to theabove embodiment, and an instruction needed to an individual applicationmay be suitably selected and allocated.

Furthermore, the encoding system of the present invention is not limitedto the bmov command, and the same encoding system may be applied toother commands. For example, the operand for indicating an operandregister is not necessarily required to the instruction code, and theinstruction and the operand register may be in one-to-one relationship.

The size of the instruction code is not limited to 16 bits.

1. A microcomputer that can process plural tasks time-divisionally andin parallel, at least one of these tasks being a specific task in whicha program looped so that an increment of instruction addresses is fixedis described, wherein one of the plural programs is described as alooped specific task in which the increment of program addresses isfixed, a program counter is usable as a timer counter, a peripheralfunction instruction for executing a peripheral function by oneinstruction is described in the specific task, the peripheral functioninstruction is set so as to indicate one or more general-purposeregisters as an operand, the CPU is designed so that the peripheralfunction instruction can be executed as one instruction, achievesinformation needed to execute the instruction concerned by ageneral-purpose register and stores information concerning an executionresult of the instruction concerned into the general-purpose registers,wherein when executing an input capture instruction as the peripheralfunction instruction, the CPU achieves edge indicating information ofthe input terminal as a condition for achieving a timer value from thegeneral-purpose register, stores the previously sampled level of theinput terminal and the present level of the input terminal into thegeneral-purpose register, achieves a timer counter value when it isjudged on the basis of the previous and present states of the inputterminal that the achieved condition is satisfied, and stores the timercounter value as a capture value into the general-purpose register. 2.The microcomputer according to claim 1, wherein the CPU is equipped witha twice-coincidence filter function of storing the previous state of theinput terminal and the present state of the input terminal in thegeneral-purpose register when executing an instruction of an inputprocessing system as the peripheral function instruction, and allowingexecution of the input processing system instruction when both thevalues are coincident with each other.
 3. The microcomputer according toclaim 2, wherein the CPU is designed so that execution or non-executionof the twice-coincidence filter function can be selected in accordancewith setting of a bit in the general-purpose register.